import java.util.*;

public class PredicateIterator implements Iterator{

	Iterator iter;
	Predicate pred;
	Object argument;
	Object next;
	
	
	public PredicateIterator (Iterator iter, Predicate pred, Object argument){
		this.iter=iter;
		this.pred=pred;
		this.argument=argument;
	}
	
	public boolean hasNext(){
	
		while(iter.hasNext()){
			next = iter.next();
			if(pred.predicate((String)next,(String)argument)) {
				return true;
			}
		}
		return false;
		
	}
	
	public Object next(){
		if(hasNext()==true){
			return next;
		}
		else throw new NoSuchElementException();
	}
	
	public void remove(){
		throw new UnsupportedOperationException();
	}
}
